import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { NzModalService } from 'ng-zorro-antd';

declare var bpm: any;
declare var ui: any;
declare var form: any;
declare var security: any;

@Component({
  templateUrl: './security.person.info.bpm.component.html'
})
export class SecurityPersonInfoBpmComponent implements OnInit {

  ss: any;
  // 流程服务
  bs: any;
  // 表单服务
  fs: any;
  // 菜单
  menu = null;
  // 字典
  genderDic: any = null;
  airportDic: any = null;
  departmentDic: any = null;
  positionDic: any = null;
  workTypeDic: any = null;
  qualificationDic: any = null;
  reQualificationResultDic: any = null;
  constructor(public route: ActivatedRoute, private modalService: NzModalService) {

    this.ss = security.SecurityService;
    this.ss.show = false;
    // 注册表单
    this.fs = new form.FormSimpleService('securityperson', {
      orderObject: { id: 0 },
      keyField: 'id',
      randomFields: ['id']
    });
    // 注册流程
    this.bs = new bpm.BpmService('securityperson', 'person_flow');
    // 注册菜单
    this.menu = new ui.TabService('bpm', 's');
    this.menu.setTab('main');
    // 注册字典
    this.genderDic = new form.DictionaryService('p_gender');
    this.genderDic.loadAll();
    this.airportDic = new form.DictionaryService('zd_airport');
    this.airportDic.loadAll();
    this.departmentDic = new form.DictionaryService('dic_department');
    this.departmentDic.loadAll();
    this.positionDic = new form.DictionaryService('p_position');
    this.positionDic.loadAll();
    this.workTypeDic = new form.DictionaryService('p_work_type');
    this.workTypeDic.loadAll();
    this.qualificationDic = new form.DictionaryService('p_qualification');
    this.qualificationDic.loadAll();
    this.reQualificationResultDic = new form.DictionaryService('p_requalification_result');
    this.reQualificationResultDic.loadAll();
  }

  ngOnInit() {
    this.initData();
  }

  initData() {
    let id = '-1';
    this.route.queryParams.subscribe((res) => {
      if (res.id) {
        id = res.id;
      }
    });
    this.fs.editRowByKey(id, (data) => {
      // 设置流程数据
      this.bs.dataKey = data.id;
      if (data.airport === undefined) {
        data.unit = this.ss.user.userDepCode[0];
        debugger;
      }

      this.bs.data = data;
      // 进来先查询流程信息
      this.bs.findWork();
    });
  }

  close() {
    window.close();
  }

  loadHistory() {
    this.menu.setTab('history');
    this.bs.loadHistory();
  }

  loadImage() {
    this.menu.setTab('image');
    this.bs.loadImage();
  }
}
